package com.app.util;


import com.app.entity.params.EmailParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author by ltl on 2021/3/14
 */
@Component
public class EmailUtil {
    @Autowired
    private JavaMailSenderImpl javaMailSender;

    //发送简单邮件
    @Async
    public String sendSimpleMail(EmailParams emailParams) {
        try {
            SimpleMailMessage smm = new SimpleMailMessage();
            smm.setFrom("dangzl1999@163.com");      //谁发的
            smm.setTo(emailParams.getToQQ());             //发给谁
            smm.setSubject(emailParams.getTheme());     //主题
            smm.setText(emailParams.getContent());
            javaMailSender.send(smm);  //邮件发送
        } catch (Exception e) {
            e.printStackTrace();
            return "发送失败！";
        }
        return "发送成功！";
    }
}
